#include <iostream>
#include <unistd.h>
#include <pthread.h>
#include <sys/types.h>

using namespace std;

/* 票数：10 */
int g_cout = 10;

void * threadFunc1(void * arg)
{

    while(g_cout > 0)
    {
        sleep(1);

        /* 下单 */
        g_cout--;
        cout << "thread1 cnt:" << g_cout << endl;
    }

    pthread_exit(NULL);
}

void * threadFunc2(void * arg)
{
    while(g_cout > 0)
    {
        sleep(1);

        /* 下单 */
        g_cout--;
        cout << "thread2 cnt:" << g_cout << endl;
    }
    pthread_exit(NULL);
}

void * threadFunc3(void * arg)
{
    while(g_cout > 0)
    {
        sleep(1);

        /* 下单 */
        g_cout--;
        cout << "thread3 cnt:" << g_cout << endl;
    }
    pthread_exit(NULL);

}

int main()
{
    pthread_t tid1;
    pthread_create(&tid1, NULL, threadFunc1, NULL);

    pthread_t tid2;
    pthread_create(&tid2, NULL, threadFunc2, NULL);

    pthread_t tid3;
    pthread_create(&tid3, NULL, threadFunc3, NULL);

    while(1)
    {
        sleep(1);
    }

    return 0;
}